﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TVShow.Framework
{
  public class Launcher : PluginBase
  {
    const int launch = 0;
    const int FileName = 1;
    const int Parameters = 2;    // optional
    const int WorkingDir = 3;    // optional
    const int Minimize = 4;      // optional 1=minimize main window
    const int WaitForExit = 5;   // optional 1=wait

    public override void ProcessMessage(TVSMessage Event) {
      if (Event.Text == "launch") {
        Launch(Event);
      }
    }

    private void Launch(TVSMessage Event) {
      if (Event[WorkingDir] != "" && System.IO.Directory.Exists(Event[WorkingDir]))
        System.IO.Directory.SetCurrentDirectory(Event[WorkingDir]);
      Shell.Launch(Event[FileName], Event[Parameters], false);
      System.IO.Directory.SetCurrentDirectory(Shell.AppPath());
      Event.Handled = true;
    }
  }
}
